from fastapi import APIRouter, Request, Query
import json
'''

    定义 API 路由和处理函数， 实例化 APIRouter 参数 prefix 添加路由前缀， tags 添加接口文档分类
    
    prefix 和 tags 这两个参数也可以在注册路由的时候定义

'''

user = APIRouter()


# user = APIRouter(prefix='/ai', tags=['user'])

@user.get('/test')
async def test(roleName: str = Query(None)):
    # 请求url：http://127.0.0.1:8000/test?roleName=admin
    return {'message': roleName}


@user.get('/pro/{id}')
async def test(id: int = None):
    # 请求url：http://127.0.0.1:8000/test/10

    with open(r"C:\Users\hk8s\Desktop\digital_grassroot\query_all_path.json","r",encoding="utf-8") as f:
        data_line = f.read()
        data = json.loads(data_line)
    print("类型：",type(data))
    # return {'message': data}
    return data

@user.post('/dev')
async def dev(data: dict):
    # 请求body数据验证为dict
    return {'message': data}
